package com.zimmur.app.mocolink.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zimmur.app.mocolink.dao.VerifyMobileLogMapper;
import com.zimmur.app.mocolink.domain.model.VerifyMobileLog;
import com.zimmur.app.mocolink.domain.util.DateUtils;
import com.zimmur.app.mocolink.service.IVerifyMobileService;

@Service
public class VerifyMobileServiceImpl implements IVerifyMobileService {

	@Autowired
	private VerifyMobileLogMapper verifyMobileLogMapper;
	@Override
	public VerifyMobileLog getInfoByMobile(String mobileNo) {
		VerifyMobileLog mobileLog = verifyMobileLogMapper.selectLastLogByMobileNo(mobileNo);
		Date now =DateUtils.getNow();
		if(mobileLog!=null && mobileLog.getIsVerify()==0 && mobileLog.getExpaireTime().after(now)){
			return mobileLog;
		}
		return null;
	}

	@Override
	public int updateInfoStatus(VerifyMobileLog mobileLog) {
		mobileLog.setVerifyTime(DateUtils.getNow());
		mobileLog.setIsVerify((short)1);
		return verifyMobileLogMapper.updateByPrimaryKeySelective(mobileLog);
	}

	@Override
	public int addMobileLog(String mobileNo, String code) {
		VerifyMobileLog verifyMobile=new VerifyMobileLog();
		verifyMobile.setMobileNo(mobileNo);
		verifyMobile.setIsVerify((short)0);
		verifyMobile.setSendTime(DateUtils.getNow());
		verifyMobile.setVerifyCode(code);
		verifyMobile.setExpaireTime(DateUtils.getAfterMinute(10));
		
		return verifyMobileLogMapper.insertSelective(verifyMobile);
	}

	

}
